<!--
#
# Copyright (c) 2014, Deem Inc. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-->
<#import "layouts/main-layout.ftl.html" as main> 
<@main.page>

<div class="container">
    <form method="post" action="/home">
        <!--Bread crumb-->
        <div class="row-fluid">
            <div class="col-md-12">
                <#if flashMsg??>
                <p class="text-success text-center">${flashMsg}</p>
                <#else>
                &nbsp;
                </#if> 

                <ul class="breadcrumb">
                    <#assign breadCrumbPath = ""> 
                    <#if breadCrumbLst?has_content>
                    <#list breadCrumbLst as breadCrumb>

                    <#if breadCrumb != "">
                    <#assign breadCrumbPath = breadCrumbPath + "/" +  breadCrumb> 
                    </#if>

                    <li><a href="/home?zkPath=${breadCrumbPath}" class="breadcrumb-select">${breadCrumb}</a></li>
                    </#list>
                    <#else>
                    <li>/</li>
                    </#if>
                </ul>

            </div>
        </div>

        <div class="row-fluid">
            <div class="col-md-3 well pre-scrollable scroll-pane" >
                <span class="glyphicon glyphicon-folder-close"></span>
                <a href="/home?zkPath=${parentPath}"><..></a>
                <br/>
                <#list nodeLst as node>
                <input type="checkbox" name="nodeChkGroup" value="${currentPath}${node}"/>
                <span class="glyphicon glyphicon-folder-close"></span>
                <a href="/home?zkPath=${currentPath}${node}">${node}</a>
                <br/>
                </#list>

            </div>
            <div class="col-md-9 pre-scrollable scroll-pane">
                <table class="table table-striped table-bordered wrap-table">
                    <thead>
                        <tr>
                            <th style="width: 4%"></th>
                            <th>Name</th>
                            <th>Value</th>
                        </tr>
                    </thead>
                    <tbody>
                        <#list leafLst as leaf>
                        <tr>
                            <td>
                                <input type="checkbox" name="propChkGroup" value="${currentPath}${leaf.name?html}"/>
                            </td>
                            <td>
                                <#if authRole?? && authRole == 'ADMIN' >
                                <#if leaf.value??>
                                <a href="#" data-toggle="modal" class="href-select" data-target="#addPropertyModal" itemprop="${leaf.strValue?html}" >${leaf.name}</a> 
                                <#else>
                                <a href="#" data-toggle="modal" class="href-select" data-target="#addPropertyModal" itemprop="" >${leaf.name}</a> 
                                </#if>
                                <#else>
                                ${leaf.name}
                                </#if>
                            </td>
                            <#if navigate?? && navigate == 'true'>
                            <td><a href="/home?zkPath=${leaf.strValue}">${leaf.strValue}</a></td>
                            <#else>
                            <td>
                                <#if leaf.value??>
                                ${leaf.strValue?html}
                                </#if>
                            </td>
                            </#if>

                        </tr>
                        </#list>
                    </tbody>
                </table>
            </div>
        </div>

        <!--Modal Dialog-->
        <div class="row-fluid">
            <div class="col-md-12">
                <input type="hidden" name="currentPath" value="${currentPath}"/>
                <input type="hidden" name="displayPath" value="${displayPath}"/>
                <input type="hidden" id="delNodeLst"  name="delNodeLst"/>
                <input type="hidden" id="delPropLst" name="delPropLst"/>

                <!-- Search Property Modal -->
                <div class="modal fade" id="searchModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">Search</h4>
                            </div>
                            <div class="modal-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">Search</span>
                                    <input type="text" id="search"  name="searchStr" class="form-control" >
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <input type="submit" id="searchBtn" name="action" value="Search" class="btn btn-primary"/>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Add Node Modal -->
                <div class="modal fade" id="addNodeModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">Add Node</h4>
                            </div>
                            <div class="modal-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">Name</span>
                                    <input type="text" name="newNode" class="form-control" placeholder="name">
                                </div>

                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <input type="submit" name="action" value="Save Node" class="btn btn-primary"/>
                            </div>
                        </div> 
                    </div>
                </div> 

                <!-- Add Property Modal -->
                <div class="modal fade" id="addPropertyModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">Add Property</h4>
                            </div>
                            <div class="modal-body">
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">Name</span>
                                    <input type="text" id="newProperty"  name="newProperty" class="form-control" placeholder="name">
                                </div>
                                <br/>
                                <div class="input-group input-group-lg">
                                    <span class="input-group-addon">Value</span>
                                    <textarea id="newValue" name="newValue" class="form-control" placeholder="value" style="resize:vertical;" ></textarea>
                                </div>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                <input type="submit" id="savePropertyBtn" name="action" value="Save Property" class="btn btn-primary"/>
                                <input type="submit" id="updatePropertyBtn" name="action" value="Update Property" class="btn btn-primary"/>
                            </div>
                        </div>
                    </div>
                </div>

                <!-- Delete Property Modal -->
                <div class="modal fade" id="deleteModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">Delete</h4>
                            </div>
                            <div class="modal-body">
                                <h3>Are you sure you want to delete?</h3>
                            </div>
                            <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">No</button>
                                <input type="submit" name="action" value="Delete" class="btn btn-primary"/>
                            </div>
                        </div>
                    </div>
                </div>

            </div>        


        </div>
    </form>
    <div class="row-fluid">
        <div class="col-md-12">
            <!-- Import Modal -->
            <form id="importForm" method="post" action="/import" enctype="multipart/form-data">
                <div class="modal fade" id="importModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
                    <div class="modal-dialog">
                        <div class="modal-content">
                            <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                                <h4 class="modal-title" id="myModalLabel">Import</h4>
                            </div>
                            <div class="modal-body" >

                                <div class="form-group">
                                    <div class="input-group input-group-lg">
                                        <span class="input-group-addon">Upload File</span>
                                        <div class="fileinput fileinput-new" data-provides="fileinput">
                                            <span class="btn btn-default btn-file">
                                                <input class="form-control" type="file" name="scmFile" size="30">
                                            </span>
                                        </div>
                                    </div>



                                    <br/>
                                    <h4 class="text-center text-primary">OR</h4>
                                    <br/>

                                    <div class="input-group input-group-lg">
                                        <span class="input-group-addon">File Path</span>
                                        <input type="hidden" id="scmServer" name="scmServer" value="${scmRepo}"/>
                                        <input type="text" id="scmFilePath"  name="scmFilePath" class="form-control" placeholder="${scmRepoPath}">
                                    </div>
                                    <br/>
                                    <div class="input-group input-group-lg">
                                        <span class="input-group-addon">Revision</span>
                                        <input type="text" id="scmFileRevision"  name="scmFileRevision" class="form-control" placeholder="head">
                                    </div>
                                    <br/>
                                    <div class="text-center">
                                        <a href="#" id="importFileView" target="_blank">View</a>
                                    </div>
                                </div>

                            </div>
                            <div class="modal-footer">
                                <div class="checkbox text-left">
                                    <label><input type="checkbox" name="scmOverwrite" value="true"> Overwrite Existing Properties</label>
                                </div>

                                <div>
                                    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                    <input type="submit" id="importBtn" name="action" value="Import" class="btn btn-primary"/>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </form>

        </div>
    </div>
</div>

</@main.page> 